package com.ruoyi.project.charge.mapper;

import com.ruoyi.project.charge.domin.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @auther:YU JIANG
 * @date:2021/7/13
 * @time:14:32
 */
@Mapper
public interface ChargeMapper {

    @Select("SELECT mr.reg_id,mr.pati_name,mr.reg_depts,mr.reg_docter,mr.reg_sdate,mc.case_complaint,mc.case_daig_info,mc.case_advise FROM med_reg mr join med_case mc on mr.reg_id = mc.reg_id where mr.reg_id=#{param1}")
    List<ChargeInfo> selectInfo(String reg_id);

    @Select("SELECT mcm.case_id,mcm.drug_id,d.drug_name,mcm.medical_num,d.drug_Rx_price,mcm.medical_price,mcm.medical_remark,mcm.pay_status FROM med_case_medical mcm join drug d on mcm. drug_id=d.drug_id where mcm.reg_id=#{param1}")
    List<ChargeMedInfo> selectMedInfo(String reg_id);

    @Select("select mcc.case_id,mcc.check_id,mcc.exam_name,mcc.exam_id,cm.case_price,cm.checkresult,mcc.check_remark,cm.pay_status from med_case_check mcc join check_mode cm on mcc.check_id=cm.check_code where mcc.reg_id=#{param1}")
    List<ChargeProjectInfo> selectProjectInfo(String reg_id);

    //修改检查项目支付状态
    @Update("update check_mode set pay_status=#{param3} where case_code=#{param1} and check_code=#{param2}")
    int updateProPay(String case_code,String check_code,String pay_status);

    //修改药品支付状态
    @Update("update med_case_medical set pay_status=#{param3} where reg_id=#{param1} and drug_id =#{param2}")
    int updateMedPay(String reg_id,String drug_id,String pay_status);

    //创建订单
    @Insert("insert into charge values(default,#{order_id},#{registration_id},#{patient_name},#{total_amount},#{payment_method},#{order_status},SYSDATE())")
    int insertCharge(Charge charge);

    //创建详情订单
    @Insert("insert into chargedetail values(#{order_id},#{drug_name},#{drug_id},#{drug_Rx_price},#{drug_price},#{drug_amount},#{type},#{status},default)")
    int insertChargeDetail(ChargeDetail chargeDetail);
}
